//
//  AppDelegate.swift
//  SeeFM_Swift
//
//  Created by CBCT_MBP on 2021/5/19.
//

import UIKit

@main

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        window = UIWindow.init(frame: UIScreen.main.bounds)
        Adapter.Base.initAppInterface(window: window!)
        self.onAppLaunch()
        
        return true
    }
    

}



extension AppDelegate {
    
    func onAppLaunch() {
        
        registerDevice()
        
    }

    func registerDevice() {
        
        SFNetwork.get(url: kAPI_check_time) { res in
            switch res {
            case .success(let res):
                let time = TimeModel.deserialize(from: res.data)
                let date = NSDate.init(timeIntervalSinceNow: 0)
                let minusValue = (time?.time ?? 0) - Int(date.timeIntervalSince1970 * 1000)
                ConfigGlobalInfo.shared.timeDiff = minusValue
                RegisterManager.shared.register { result in
                    
                }
                break

            case .fail(let error):
                AppHelper.showInfo(info: error.errMsg)
                break
                
            }
        }

    }
    
}
